<template>
	<view style="padding-bottom: 60rpx;">
		<rich-text class="detail" :nodes="html_nodes"></rich-text>
		<view style="position: fixed;bottom: 0;width: 100%;">
			<view class="dflex-c padding-tb-sm flex1 bg-base use-hover" @click="toContact()">业务咨询</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	// #ifdef MP-ALIPAY
	import aliParse from 'mini-html-parser2';
	// #endif
	const mini_obj = uniCloud.importObject('wmz-mini')
	export default {
		computed: {
			...mapState(['islogin'])
		},
		data() {
			return {
				content: "",
				html_nodes: []
			}
		},
		async onLoad() {
			let appId
			let shopId
			let spaceId
			let tAppId = "def1da4565222ccc05d977461539689c"
			let tShopId = "def1da4565222ccc05d977461539689c"
			// #ifdef MP-ALIPAY
			const extJson = my.getExtConfigSync();
			if (extJson) {
				appId = extJson.appId;
				shopId = extJson.shopId;
				spaceId = extJson.spaceId;
			} else {
				appId = tAppId;
				shopId = tShopId
				let templateId = my.getAppIdSync().appId
				uni.setStorageSync("templateId", templateId)
			}
			// #endif
			// #ifdef MP-WEIXIN
			const ext = uni.getExtConfigSync()
			if (ext && ext.appId) {
				appId = ext.appId;
				shopId = ext.shopId;
				spaceId = ext.spaceId;
			} else {
				appId = tAppId;
				shopId = tShopId
				const accountInfo = wx.getAccountInfoSync();
				uni.setStorageSync("templateId", accountInfo.miniProgram.appId)
			}
			// #endif
			uni.setStorageSync('wmzmall_user_app_id', appId)
			uni.setStorageSync('wmzmall_user_shop_id', shopId)
			uni.setStorageSync('wmzmall_user_space_id', spaceId)
			this.loadData()
			
			if(this.islogin){
				let res = await this.$func.wmzmall.call('entitlement/list', {
					skip:0,
					limit:1
				});
				if (res.code === 200) {
					let data=res.datas.data
					if(data.length>0){
						uni.navigateTo({
							url: "/pages/entitlement/order"
						})
						return
					}
				}
			}
		},
		methods: {
			async loadData() {

				const res = await mini_obj.getAbout({
					shop_id: uni.getStorageSync('wmzmall_user_shop_id')
				})
				let content = res.data.content
				// #ifndef MP-ALIPAY
				this.html_nodes = content
				// #endif
				// #ifdef MP-ALIPAY
				this.html_nodes = [];
				aliParse(content, (err, nodes) => {
					if (!err) {
						this.html_nodes = nodes;
					}
				});
				// #endif
			},
			toContact() {
				uni.navigateTo({
					url: '../contact/contact'
				});
			}
		}
	}
</script>

<style>
	.detail {
		overflow: hidden;
		-webkit-touch-callout: none;
		/* padding: 20rpx;	 */
	}
</style>